<template>
    <el-menu style="z-index:1;" router :default-active="routerName" unique-opened :collapse="isCollapse" background-color="#FBFBFB" text-color="#676767" active-text-color="#006644" :collapse-transition="false" v-for="(ele,index) in routerList" :key="index">
        <el-menu-item :index="ele.path" v-if='!ele.children'>
            <span>{{ele.meta.title}}</span>
        </el-menu-item>
        <el-sub-menu :index="ele.path" v-else>
            <template #title>
                <span>{{ele.meta.title}}</span>
            </template>
            <template v-for="(ele2,index2) in ele.children">
                <el-sub-menu v-if='ele2.children' :index="ele2.path" :key="index2">
                    <template #title>
                        <span>{{ele2.meta.title}}</span>
                    </template>
                    <el-menu-item-group v-for="(ele3,index3) in ele2.children" :index="ele3.path" :key="ele3.name">
                        <el-menu-item :key="index3" :index="ele3.path">
                            <span>{{ele3.meta.title}}</span>
                        </el-menu-item>
                    </el-menu-item-group>
                </el-sub-menu>
                <el-menu-item v-else :index="ele2.path" :key=" 'q' + index2">
                    <template #title>
                        <span>{{ele2.meta.title}}</span>
                    </template>
                </el-menu-item>
            </template> 
        </el-sub-menu>
    </el-menu>
</template>

<script lang="ts">
import router from "../router/router"
export default {
    name: 'siderBar',
    data () {
        return { 
            routerList: [],
            routerName: '',
        }
    },
    computed:{
        isCollapse() {
            return !this.$store.state.isCollapsed
        },
        routes() {
            const a = this.$store.dispatch("generateRoutes")
            return this.$store.state.routes
        },
    },
    mounted () {
        this.routerList = this.routes
    },
    methods: {
        goRouter(name, item) {
            if (item.name === this.$route.name) {
                return 
            }
            this.$router.push({
                name
            })
        }
    }
    
}
</script>